package com.authine.cloudpivot.engine.domain.system;

import com.authine.cloudpivot.engine.domain.BaseEntity;
import com.authine.cloudpivot.engine.enums.status.BizServiceStatus;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name = BizServiceLog.TABLENAME, indexes = {@Index(name = "idx_log_biz_service_id", unique = true, columnList = "id")})
@Setter
@Getter
@ToString
public class BizServiceLog extends BaseEntity {


    private static final long serialVersionUID = 1L;

    public static final String TABLENAME = "h_log_biz_service";

    /**
     * 业务服务编码
     */
    @Column(length = 40)
    private String code;
    /**
     * 业务方法名称
     */
    @Column(length = 120)
    private String methodName;

    /**
     * 输入参数
     */
    @Lob
    private String params;

    /**
     * 输出参数
     */
    @Lob
    @Column
    private String result;

    /**
     * 是否成功
     */
    @Enumerated(EnumType.STRING)
    @Column(length = 20)
    private BizServiceStatus bizServiceStatus;

    /**
     * 异常信息
     */
    @Lob
    @Column
    private String exception;

    /**
     * 开始时间
     */
    @Column(length = 120)
    private Date startTime;

    /**
     * 结束时间
     */
    @Column(length = 120)
    private Date endTime;

    /**
     * 耗时
     */
    @Column(length = 10)
    private Long usedTime;

    /**
     * 运行服务器
     */
    @Column(length = 200)
    private String server;

    /**
     * 业务模型编码
     */
    @Column(length = 40)
    private String schemaCode;

    /**
     * 业务对象ID
     */
    @Column(length = 200)
    private String bizObjectId;

    @Lob
    @Column
    private String options;

    @Column(length = 120)
    private Date createdTime = new Date();

    /**
     * 扩展日志由各调用方自己定义
     */
    @Column
    private String extensionLog;

    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date getStartTime() {
        return startTime;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date getEndTime() {
        return endTime;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date getCreatedTime() {
        return createdTime;
    }

    @Override
    @Transient
    public String getTableName() {
        return TABLENAME;
    }
}
